package cn.signUpSystem.action;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.signUpSystem.pojo.Admin;
import cn.signUpSystem.pojo.MyTime;
import cn.signUpSystem.util.TimeUtil;

@Controller
@Scope("prototype")
public class AdminAction extends BaseAction<Admin> {

	private String year;

	private String month;

	private String day;

	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public String getMonth() {
		return month;
	}

	public void setMonth(String month) {
		this.month = month;
	}

	public String getDay() {
		return day;
	}

	public void setDay(String day) {
		this.day = day;
	}

	/**
	 * 判断管理员登陆
	 */
	public String login() {
		if (adminService.login(model)) {
			session.put("admin", model);
			return "toAdminIndex";
		}
		request.put("failMessage", "用户名或密码错误");
		return "toLoginUI";
	}

	/**
	 * 判断是否已经登陆
	 */
	public String hadLogined() {
		if (session.get("admin") != null) {
			return "toAdminIndex";
		}
		return "toLoginUI";
	}

	/**
	 * 设置报名截止时间UI
	 */
	public String setTimeUI() {
		request.put("setTime", "setTime");
		return "toAdminIndexUI";
	}

	/**
	 * 设置报名截止时间
	 */
	public String setTime() {
		MyTime myTime = null;
		boolean timeIsEffective = TimeUtil.judgeTime(year, month, day);
		if (myTimeService.queryAll() == null) {
			myTime = new MyTime();
			myTime.setYear(year);
			myTime.setMonth(month);
			myTime.setDay(day);
			myTimeService.add(myTime);
		} else {
			myTime = myTimeService.queryOne(1);
			myTime.setYear(year);
			myTime.setMonth(month);
			myTime.setDay(day);
			myTimeService.update(myTime);
		}
		application.put("timeIsEffective", timeIsEffective);
		return "toAdminIndexUI";
	}
}
